// pages/weather/weather.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    AppKey:"c102b033ff4ec17dc38977b3c96e5320",
    current: {
      temperature: 26,       // 当前温度
      info: "晴",     // 天气状况
      direct: "东南风",
      power: 3,        // 风力等级
      humidity: 65,      // 湿度百分比
      aqi: "",   // 空气质量文字
    }
  },
  weatherData:[
    {
      date: "10/01",
      temperature: 24,
      weather: "晴",
      direct: "东南风",
    },
    {
      date: "10/02",
      temperature: 24,
      weather: "多云",
      direct: "西南风",
    },
    {
      date: "10/03",
      temperature: 24,
      weather: "小雨",
      direct: "东北风",
    },
    {
      date: "10/04",
      temperature: 24,
      weather: "阴",
      direct: "北风",
    },
    {
      date: "10/05",
      temperature: 24,
      weather: "晴",
      direct: "西北风",
    }
  ],
  onShow() {
    let that = this;
    wx.request({
      url:"http://apis.juhe.cn/simpleWeather/query",
      method:"GET",
      data:{
        city:"福州",
        key:that.data.AppKey
      },
      success(res){
        console.log("查询天气成功",res)
        that.setData({
          'current':res.data.result.realtime,
          'weatherData':res.data.result.future
        })
      },
      fail(res){
        console.log("查询天气失败: ",res)
      },
      complete(res){
        console.log("查询天气完成",res)
      }
    })
  },
})